package org.jivesoftware.smackx.workgroup.packet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class TranscriptsProvider
  implements IQProvider
{
  private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");

  static
  {
    UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
  }

  private List<Transcripts.AgentDetail> parseAgents(XmlPullParser paramXmlPullParser)
    throws IOException, XmlPullParserException
  {
    label19: int j;
    ArrayList localArrayList = new ArrayList();
    String str = null;
    Object localObject1 = null;
    Object localObject2 = null;
    int i = 0;
    while (true)
    {
      if (i != 0)
        return localArrayList;
      j = paramXmlPullParser.next();
      if (j != 2)
        break label159;
      if (!(paramXmlPullParser.getName().equals("agentJID")))
        break;
      str = paramXmlPullParser.nextText();
    }
    if (paramXmlPullParser.getName().equals("joinTime"));
    try
    {
      while (true)
      {
        Date localDate2 = UTC_FORMAT.parse(paramXmlPullParser.nextText());
        localObject1 = localDate2;
      }
      label159: if (paramXmlPullParser.getName().equals("leftTime"));
    }
    catch (ParseException localParseException2)
    {
      try
      {
        do
          while (true)
          {
            do
              while (true)
              {
                do
                  while (true)
                  {
                    Date localDate1 = UTC_FORMAT.parse(paramXmlPullParser.nextText());
                    localObject2 = localDate1;
                  }
                while (!(paramXmlPullParser.getName().equals("agent")));
                str = null;
                localObject1 = null;
                localObject2 = null;
              }
            while (j != 3);
            if (!(paramXmlPullParser.getName().equals("agents")))
              break;
            i = 1;
          }
        while (!(paramXmlPullParser.getName().equals("agent")));
        localArrayList.add(new Transcripts.AgentDetail(str, localObject1, localObject2));
      }
      catch (ParseException localParseException1)
      {
        break label19:
        localParseException2 = localParseException2;
      }
    }
  }

  private Transcripts.TranscriptSummary parseSummary(XmlPullParser paramXmlPullParser)
    throws IOException, XmlPullParserException
  {
    String str = paramXmlPullParser.getAttributeValue("", "sessionID");
    Object localObject1 = null;
    Object localObject2 = null;
    Object localObject3 = new ArrayList();
    int i = 0;
    if (i != 0)
      label28: return new Transcripts.TranscriptSummary(str, (Date)localObject1, (Date)localObject2, (List)localObject3);
    int j = paramXmlPullParser.next();
    if ((j != 2) || (paramXmlPullParser.getName().equals("joinTime")));
    try
    {
      while (true)
      {
        Date localDate2 = UTC_FORMAT.parse(paramXmlPullParser.nextText());
        localObject1 = localDate2;
      }
      if (paramXmlPullParser.getName().equals("leftTime"));
    }
    catch (ParseException localParseException2)
    {
      try
      {
        do
          while (true)
          {
            do
              while (true)
              {
                Date localDate1 = UTC_FORMAT.parse(paramXmlPullParser.nextText());
                localObject2 = localDate1;
              }
            while (!(paramXmlPullParser.getName().equals("agents")));
            localObject3 = parseAgents(paramXmlPullParser);
          }
        while ((j != 3) || (!(paramXmlPullParser.getName().equals("transcript"))));
        i = 1;
      }
      catch (ParseException localParseException1)
      {
        break label28:
        localParseException2 = localParseException2;
      }
    }
  }

  public IQ parseIQ(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    String str = paramXmlPullParser.getAttributeValue("", "userID");
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    while (true)
    {
      int j;
      label80: 
      do
        while (true)
        {
          do
          {
            if (i != 0)
              return new Transcripts(str, localArrayList);
            j = paramXmlPullParser.next();
            if (j != 2)
              break label80;
          }
          while (!(paramXmlPullParser.getName().equals("transcript")));
          localArrayList.add(parseSummary(paramXmlPullParser));
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("transcripts"))));
      i = 1;
    }
  }
}